package com.ge.med.cchelper.popup.job;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import com.ge.med.cchelper.bean.Response;
import com.ge.med.cchelper.util.LogUtil;
import com.ge.med.cchelper.util.SSLhelper;

public class DeleteTempJob extends BaseJob{

	private String deleteDirCmd;
	public DeleteTempJob(String target) {
		this(target,false);
	}
	public DeleteTempJob(String target,boolean isFile) {
		super("Deleting temporary "+(isFile?"file":"directory"));
		if(isFile){
			deleteDirCmd = "rm -f "+target;
		}else{
			deleteDirCmd = "mkdir -p " + emptyDir + ";/usr/bin/rsync --delete -a -H "
					+ emptyDir + " " + target;
		}
	}

	protected IStatus start(IProgressMonitor arg0) {
		
		SSLhelper sslHelper = new SSLhelper(csession);
		Response res2 = sslHelper.execute(deleteDirCmd);
		if (res2.getStatus() != 0) {
			LogUtil.err("The Temp files Delete operation failed in host");
		}
		return Status.OK_STATUS;
	}

}
